package com.cy.store.config;

import com.cy.store.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.time.Year;

/**
 * @author ZhangSir
 */
@Configuration
public class LoginConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器并添加拦截规则
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                //也可以用一个List<String> 来设置排除拦截的资源
                //拦截器也要放行接口的请求，不然就报错
                .excludePathPatterns(
                        "/address/**", "/bootstrap3/**",
                        "/cart/**", "/css/**",
                        "/district/**", "/file/**",
                        "/images/**", "/js/**", "/kaptcha/**", "/order/**",
                        "/product/**", "/user/**", "/web/components/**", "/web/index.html",
                        "/web/login.html", "/web/product.html",
                        "/web/register.html", "/web/search.html"
                );
    }
}
